import axios from "axios";
import { ElMessage } from 'element-plus'
import 'element-plus/theme-chalk/el-message.css'
import Cookies from 'js-cookie'

const http  = axios.create({
    baseURL:'http://192.168.43.49:8080/shixun',
    timeout:5000
})

// axios请求拦截器
http.interceptors.request.use(config => {
  const token = Cookies.get('token')
  if (token) {
    // console.log(token);
    config.headers['token'] = token
  }
    return config
  }, e => Promise.reject(e))
  
  // axios响应式拦截器
  // http.interceptors.response.use(res => res.data, e => {
  //   ElMessage({
  //     type:'false',
  //     message:e.response.data.message
  //   })
  //   return Promise.reject(e)
  // })
  http.interceptors.response.use((response)=> {
    // console.log(response);
      return response.data;
    },(error)=> {
      ElMessage({
            type:'warning',
            message:e.response.data.message
          })
          return Promise.reject(error)
  })

export default http